using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using ctsu.Admin.BusLogic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.VisualBasic;
using ctsu.Data;

namespace ctsu.Admin.Forms
{
	public class FormArpUtils : System.Windows.Forms.Form
	{
		private Hashtable _htSettings;
		private bool _exportsCleaned;

		#region windows controls
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.CheckBox chkGetActiveProtosExec;
		private System.Windows.Forms.Button btnGetActiveProtos;
		private System.Windows.Forms.CheckBox chkConn;
		private System.Windows.Forms.Button btnTestArpConn;
		private System.Windows.Forms.DataGrid dgActiveProtocols;
		private System.Windows.Forms.Button btnExportProtos;
		private System.Windows.Forms.CheckBox chkExportProtosOK;
		private System.Windows.Forms.TabPage tabPage3;
		private Syncfusion.Windows.Forms.Tools.DateTimePickerAdv BeginDate;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private Syncfusion.Windows.Forms.Tools.DateTimePickerAdv EndDate;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Button btnCompact;
		private System.Windows.Forms.Button btnReplace;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TabPage tabPage4;
		private System.Windows.Forms.DataGrid dgActiveInvestig;
		private System.Windows.Forms.TabPage tabPage5;
		private System.Windows.Forms.DataGrid dgExpInvestigators;
		private System.Windows.Forms.TabPage tabPage6;
		private System.Windows.Forms.DataGrid dgExpInvProt;
		private System.Windows.Forms.Button btnExpAncillaries;
		private System.Windows.Forms.CheckBox chkExpAncillaries;
		private System.Windows.Forms.TabPage tabPage7;
		private System.Windows.Forms.DataGrid dgExpAncillaries;
		private System.Windows.Forms.Button btnExpEthnicity;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.Button btnMisc;
		private System.Windows.Forms.Button btnTestAdmCen;
		private System.Windows.Forms.Button btnTestOutpatCen;
		private System.Windows.Forms.Button btnTestScatNursHrs;
		private System.Windows.Forms.Button btnTestMyRound;
		private System.Windows.Forms.TextBox txt1;
		private System.Windows.Forms.TextBox txt2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btnCenIpSb;
		private System.Windows.Forms.Button btnTestCenOpAge;
		private System.Windows.Forms.Button btnTestCenPS;
		private System.Windows.Forms.Button btnTestCenOpHrs;
		private System.Windows.Forms.Button btnTestRateChangeDates;
		private System.Windows.Forms.Button btnAdmissionDaysByCat;
		private System.Windows.Forms.Button btnOutpatientVisitsByCat;
		private System.Windows.Forms.Button btnScatNurseHoursByCat;
		private System.Windows.Forms.TextBox txtProtocols;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.CheckBox chkTitle;
		private System.Windows.Forms.CheckBox chkLongTitle;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button btnProperCase;
		private System.Windows.Forms.DataGrid dgExpProtocols;
		#endregion windows controls

		public FormArpUtils()
		{
			InitializeComponent();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.btnExpEthnicity = new System.Windows.Forms.Button();
			this.chkExpAncillaries = new System.Windows.Forms.CheckBox();
			this.btnExpAncillaries = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btnTestRateChangeDates = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.txt2 = new System.Windows.Forms.TextBox();
			this.txt1 = new System.Windows.Forms.TextBox();
			this.btnTestMyRound = new System.Windows.Forms.Button();
			this.btnTestScatNursHrs = new System.Windows.Forms.Button();
			this.btnTestOutpatCen = new System.Windows.Forms.Button();
			this.btnTestAdmCen = new System.Windows.Forms.Button();
			this.btnMisc = new System.Windows.Forms.Button();
			this.chkConn = new System.Windows.Forms.CheckBox();
			this.btnTestArpConn = new System.Windows.Forms.Button();
			this.btnCompact = new System.Windows.Forms.Button();
			this.btnReplace = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnSave = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.EndDate = new Syncfusion.Windows.Forms.Tools.DateTimePickerAdv();
			this.label1 = new System.Windows.Forms.Label();
			this.BeginDate = new Syncfusion.Windows.Forms.Tools.DateTimePickerAdv();
			this.chkExportProtosOK = new System.Windows.Forms.CheckBox();
			this.btnExportProtos = new System.Windows.Forms.Button();
			this.chkGetActiveProtosExec = new System.Windows.Forms.CheckBox();
			this.btnGetActiveProtos = new System.Windows.Forms.Button();
			this.btnAdmissionDaysByCat = new System.Windows.Forms.Button();
			this.btnOutpatientVisitsByCat = new System.Windows.Forms.Button();
			this.btnScatNurseHoursByCat = new System.Windows.Forms.Button();
			this.btnCenIpSb = new System.Windows.Forms.Button();
			this.btnTestCenOpAge = new System.Windows.Forms.Button();
			this.btnTestCenOpHrs = new System.Windows.Forms.Button();
			this.btnTestCenPS = new System.Windows.Forms.Button();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.dgActiveProtocols = new System.Windows.Forms.DataGrid();
			this.tabPage4 = new System.Windows.Forms.TabPage();
			this.dgActiveInvestig = new System.Windows.Forms.DataGrid();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.dgExpProtocols = new System.Windows.Forms.DataGrid();
			this.tabPage5 = new System.Windows.Forms.TabPage();
			this.dgExpInvestigators = new System.Windows.Forms.DataGrid();
			this.tabPage6 = new System.Windows.Forms.TabPage();
			this.dgExpInvProt = new System.Windows.Forms.DataGrid();
			this.tabPage7 = new System.Windows.Forms.TabPage();
			this.dgExpAncillaries = new System.Windows.Forms.DataGrid();
			this.txtProtocols = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.chkTitle = new System.Windows.Forms.CheckBox();
			this.chkLongTitle = new System.Windows.Forms.CheckBox();
			this.label5 = new System.Windows.Forms.Label();
			this.btnProperCase = new System.Windows.Forms.Button();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.EndDate)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.EndDate.Calendar)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.BeginDate)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.BeginDate.Calendar)).BeginInit();
			this.tabPage2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgActiveProtocols)).BeginInit();
			this.tabPage4.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgActiveInvestig)).BeginInit();
			this.tabPage3.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgExpProtocols)).BeginInit();
			this.tabPage5.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgExpInvestigators)).BeginInit();
			this.tabPage6.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgExpInvProt)).BeginInit();
			this.tabPage7.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgExpAncillaries)).BeginInit();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Controls.Add(this.tabPage4);
			this.tabControl1.Controls.Add(this.tabPage3);
			this.tabControl1.Controls.Add(this.tabPage5);
			this.tabControl1.Controls.Add(this.tabPage6);
			this.tabControl1.Controls.Add(this.tabPage7);
			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Multiline = true;
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(824, 534);
			this.tabControl1.TabIndex = 5;
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.Add(this.btnProperCase);
			this.tabPage1.Controls.Add(this.label5);
			this.tabPage1.Controls.Add(this.chkLongTitle);
			this.tabPage1.Controls.Add(this.chkTitle);
			this.tabPage1.Controls.Add(this.label4);
			this.tabPage1.Controls.Add(this.txtProtocols);
			this.tabPage1.Controls.Add(this.checkBox1);
			this.tabPage1.Controls.Add(this.btnExpEthnicity);
			this.tabPage1.Controls.Add(this.chkExpAncillaries);
			this.tabPage1.Controls.Add(this.btnExpAncillaries);
			this.tabPage1.Controls.Add(this.groupBox1);
			this.tabPage1.Controls.Add(this.btnExit);
			this.tabPage1.Controls.Add(this.btnSave);
			this.tabPage1.Controls.Add(this.label2);
			this.tabPage1.Controls.Add(this.EndDate);
			this.tabPage1.Controls.Add(this.label1);
			this.tabPage1.Controls.Add(this.BeginDate);
			this.tabPage1.Controls.Add(this.chkExportProtosOK);
			this.tabPage1.Controls.Add(this.btnExportProtos);
			this.tabPage1.Controls.Add(this.chkGetActiveProtosExec);
			this.tabPage1.Controls.Add(this.btnGetActiveProtos);
			this.tabPage1.Controls.Add(this.btnAdmissionDaysByCat);
			this.tabPage1.Controls.Add(this.btnOutpatientVisitsByCat);
			this.tabPage1.Controls.Add(this.btnScatNurseHoursByCat);
			this.tabPage1.Controls.Add(this.btnCenIpSb);
			this.tabPage1.Controls.Add(this.btnTestCenOpAge);
			this.tabPage1.Controls.Add(this.btnTestCenOpHrs);
			this.tabPage1.Controls.Add(this.btnTestCenPS);
			this.tabPage1.Location = new System.Drawing.Point(4, 22);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(816, 508);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Main";
			// 
			// checkBox1
			// 
			this.checkBox1.Enabled = false;
			this.checkBox1.Location = new System.Drawing.Point(152, 160);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(96, 16);
			this.checkBox1.TabIndex = 23;
			this.checkBox1.Text = "Executed OK";
			// 
			// btnExpEthnicity
			// 
			this.btnExpEthnicity.Location = new System.Drawing.Point(8, 160);
			this.btnExpEthnicity.Name = "btnExpEthnicity";
			this.btnExpEthnicity.Size = new System.Drawing.Size(136, 32);
			this.btnExpEthnicity.TabIndex = 22;
			this.btnExpEthnicity.Text = "Export Ethnicity To Arp";
			this.btnExpEthnicity.Click += new System.EventHandler(this.btnExpEthnicity_Click);
			// 
			// chkExpAncillaries
			// 
			this.chkExpAncillaries.Enabled = false;
			this.chkExpAncillaries.Location = new System.Drawing.Point(152, 120);
			this.chkExpAncillaries.Name = "chkExpAncillaries";
			this.chkExpAncillaries.Size = new System.Drawing.Size(96, 16);
			this.chkExpAncillaries.TabIndex = 21;
			this.chkExpAncillaries.Text = "Executed OK";
			// 
			// btnExpAncillaries
			// 
			this.btnExpAncillaries.Location = new System.Drawing.Point(8, 120);
			this.btnExpAncillaries.Name = "btnExpAncillaries";
			this.btnExpAncillaries.Size = new System.Drawing.Size(136, 32);
			this.btnExpAncillaries.TabIndex = 20;
			this.btnExpAncillaries.Text = "Export Ancillaries To Arp";
			this.btnExpAncillaries.Click += new System.EventHandler(this.btnExpAncillaries_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnTestRateChangeDates);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txt2);
			this.groupBox1.Controls.Add(this.txt1);
			this.groupBox1.Controls.Add(this.btnTestMyRound);
			this.groupBox1.Controls.Add(this.btnTestScatNursHrs);
			this.groupBox1.Controls.Add(this.btnTestOutpatCen);
			this.groupBox1.Controls.Add(this.btnTestAdmCen);
			this.groupBox1.Controls.Add(this.btnMisc);
			this.groupBox1.Controls.Add(this.chkConn);
			this.groupBox1.Controls.Add(this.btnTestArpConn);
			this.groupBox1.Controls.Add(this.btnCompact);
			this.groupBox1.Controls.Add(this.btnReplace);
			this.groupBox1.Location = new System.Drawing.Point(432, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(376, 240);
			this.groupBox1.TabIndex = 19;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Test Utilities";
			// 
			// btnTestRateChangeDates
			// 
			this.btnTestRateChangeDates.Location = new System.Drawing.Point(160, 208);
			this.btnTestRateChangeDates.Name = "btnTestRateChangeDates";
			this.btnTestRateChangeDates.Size = new System.Drawing.Size(136, 24);
			this.btnTestRateChangeDates.TabIndex = 34;
			this.btnTestRateChangeDates.Text = "Test Rate Change Dates";
			this.btnTestRateChangeDates.Click += new System.EventHandler(this.btnTestRateChangeDates_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(248, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 16);
			this.label3.TabIndex = 29;
			this.label3.Text = "Rounded:";
			// 
			// txt2
			// 
			this.txt2.Location = new System.Drawing.Point(320, 72);
			this.txt2.Name = "txt2";
			this.txt2.Size = new System.Drawing.Size(48, 20);
			this.txt2.TabIndex = 28;
			this.txt2.Text = "";
			// 
			// txt1
			// 
			this.txt1.Location = new System.Drawing.Point(320, 40);
			this.txt1.Name = "txt1";
			this.txt1.Size = new System.Drawing.Size(48, 20);
			this.txt1.TabIndex = 27;
			this.txt1.Text = "";
			// 
			// btnTestMyRound
			// 
			this.btnTestMyRound.Location = new System.Drawing.Point(168, 40);
			this.btnTestMyRound.Name = "btnTestMyRound";
			this.btnTestMyRound.Size = new System.Drawing.Size(144, 23);
			this.btnTestMyRound.TabIndex = 26;
			this.btnTestMyRound.Text = "Test Custon Round Func";
			this.btnTestMyRound.Click += new System.EventHandler(this.btnTestMyRound_Click);
			// 
			// btnTestScatNursHrs
			// 
			this.btnTestScatNursHrs.Location = new System.Drawing.Point(8, 208);
			this.btnTestScatNursHrs.Name = "btnTestScatNursHrs";
			this.btnTestScatNursHrs.Size = new System.Drawing.Size(136, 23);
			this.btnTestScatNursHrs.TabIndex = 22;
			this.btnTestScatNursHrs.Text = "Test ScatNursHrs Census";
			this.btnTestScatNursHrs.Click += new System.EventHandler(this.btnTestScatNursHrs_Click);
			// 
			// btnTestOutpatCen
			// 
			this.btnTestOutpatCen.Location = new System.Drawing.Point(8, 176);
			this.btnTestOutpatCen.Name = "btnTestOutpatCen";
			this.btnTestOutpatCen.Size = new System.Drawing.Size(136, 23);
			this.btnTestOutpatCen.TabIndex = 21;
			this.btnTestOutpatCen.Text = "Test Outpat Census";
			this.btnTestOutpatCen.Click += new System.EventHandler(this.btnTestOutpatCen_Click);
			// 
			// btnTestAdmCen
			// 
			this.btnTestAdmCen.Location = new System.Drawing.Point(8, 144);
			this.btnTestAdmCen.Name = "btnTestAdmCen";
			this.btnTestAdmCen.Size = new System.Drawing.Size(136, 23);
			this.btnTestAdmCen.TabIndex = 20;
			this.btnTestAdmCen.Text = "Test Admission Census";
			this.btnTestAdmCen.Click += new System.EventHandler(this.btnTestAdmCen_Click);
			// 
			// btnMisc
			// 
			this.btnMisc.Location = new System.Drawing.Point(8, 112);
			this.btnMisc.Name = "btnMisc";
			this.btnMisc.Size = new System.Drawing.Size(136, 23);
			this.btnMisc.TabIndex = 19;
			this.btnMisc.Text = "Misc Test";
			this.btnMisc.Click += new System.EventHandler(this.btnMisc_Click);
			// 
			// chkConn
			// 
			this.chkConn.Enabled = false;
			this.chkConn.Location = new System.Drawing.Point(144, 16);
			this.chkConn.Name = "chkConn";
			this.chkConn.Size = new System.Drawing.Size(104, 16);
			this.chkConn.TabIndex = 6;
			this.chkConn.Text = "Connection OK";
			// 
			// btnTestArpConn
			// 
			this.btnTestArpConn.Location = new System.Drawing.Point(8, 16);
			this.btnTestArpConn.Name = "btnTestArpConn";
			this.btnTestArpConn.Size = new System.Drawing.Size(136, 23);
			this.btnTestArpConn.TabIndex = 5;
			this.btnTestArpConn.Text = "Test Arp Connection";
			this.btnTestArpConn.Click += new System.EventHandler(this.btnTestArpConn_Click);
			// 
			// btnCompact
			// 
			this.btnCompact.Location = new System.Drawing.Point(8, 48);
			this.btnCompact.Name = "btnCompact";
			this.btnCompact.Size = new System.Drawing.Size(136, 23);
			this.btnCompact.TabIndex = 17;
			this.btnCompact.Text = "Compact Database";
			this.btnCompact.Click += new System.EventHandler(this.btnCompact_Click);
			// 
			// btnReplace
			// 
			this.btnReplace.Location = new System.Drawing.Point(8, 80);
			this.btnReplace.Name = "btnReplace";
			this.btnReplace.Size = new System.Drawing.Size(152, 23);
			this.btnReplace.TabIndex = 18;
			this.btnReplace.Text = "Replace Db With Compact";
			this.btnReplace.Click += new System.EventHandler(this.btnReplace_Click);
			// 
			// btnExit
			// 
			this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnExit.Location = new System.Drawing.Point(360, 480);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(104, 23);
			this.btnExit.TabIndex = 16;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnSave
			// 
			this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnSave.Location = new System.Drawing.Point(248, 480);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(104, 23);
			this.btnSave.TabIndex = 15;
			this.btnSave.Text = "Save Settings";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(184, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 14;
			this.label2.Text = "End date:";
			// 
			// EndDate
			// 
			// 
			// EndDate.Calendar
			// 
			this.EndDate.Calendar.AllowMultipleSelection = false;
			this.EndDate.Calendar.Culture = new System.Globalization.CultureInfo("");
			this.EndDate.Calendar.DaysFont = new System.Drawing.Font("Verdana", 8F);
			this.EndDate.Calendar.DaysHeaderInterior = new Syncfusion.Drawing.BrushInfo(Syncfusion.Drawing.GradientStyle.Vertical, System.Drawing.Color.AntiqueWhite, System.Drawing.Color.PeachPuff);
			this.EndDate.Calendar.Dock = System.Windows.Forms.DockStyle.Fill;
			this.EndDate.Calendar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.EndDate.Calendar.Location = new System.Drawing.Point(0, 0);
			this.EndDate.Calendar.MinValue = new System.DateTime(1753, 1, 1, 0, 0, 0, 0);
			this.EndDate.Calendar.Name = "monthCalendar";
			// 
			// EndDate.Calendar.NoneButton
			// 
			this.EndDate.Calendar.NoneButton.Location = new System.Drawing.Point(194, 0);
			this.EndDate.Calendar.Size = new System.Drawing.Size(266, 174);
			this.EndDate.Calendar.SizeToFit = true;
			this.EndDate.Calendar.Style = Syncfusion.Windows.Forms.VisualStyle.Default;
			this.EndDate.Calendar.TabIndex = 0;
			// 
			// EndDate.Calendar.TodayButton
			// 
			this.EndDate.Calendar.TodayButton.Location = new System.Drawing.Point(0, 0);
			this.EndDate.Calendar.TodayButton.Size = new System.Drawing.Size(194, 20);
			this.EndDate.CalendarFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.EndDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
			this.EndDate.Location = new System.Drawing.Point(240, 8);
			this.EndDate.Name = "EndDate";
			this.EndDate.NullString = "";
			this.EndDate.ShowCheckBox = false;
			this.EndDate.Size = new System.Drawing.Size(96, 20);
			this.EndDate.TabIndex = 13;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(64, 16);
			this.label1.TabIndex = 12;
			this.label1.Text = "Begin date:";
			// 
			// BeginDate
			// 
			// 
			// BeginDate.Calendar
			// 
			this.BeginDate.Calendar.AllowMultipleSelection = false;
			this.BeginDate.Calendar.Culture = new System.Globalization.CultureInfo("");
			this.BeginDate.Calendar.DaysFont = new System.Drawing.Font("Verdana", 8F);
			this.BeginDate.Calendar.DaysHeaderInterior = new Syncfusion.Drawing.BrushInfo(Syncfusion.Drawing.GradientStyle.Vertical, System.Drawing.Color.AntiqueWhite, System.Drawing.Color.PeachPuff);
			this.BeginDate.Calendar.Dock = System.Windows.Forms.DockStyle.Fill;
			this.BeginDate.Calendar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.BeginDate.Calendar.Location = new System.Drawing.Point(0, 0);
			this.BeginDate.Calendar.MinValue = new System.DateTime(1753, 1, 1, 0, 0, 0, 0);
			this.BeginDate.Calendar.Name = "monthCalendar";
			// 
			// BeginDate.Calendar.NoneButton
			// 
			this.BeginDate.Calendar.NoneButton.Location = new System.Drawing.Point(194, 0);
			this.BeginDate.Calendar.Size = new System.Drawing.Size(266, 174);
			this.BeginDate.Calendar.SizeToFit = true;
			this.BeginDate.Calendar.Style = Syncfusion.Windows.Forms.VisualStyle.Default;
			this.BeginDate.Calendar.TabIndex = 0;
			// 
			// BeginDate.Calendar.TodayButton
			// 
			this.BeginDate.Calendar.TodayButton.Location = new System.Drawing.Point(0, 0);
			this.BeginDate.Calendar.TodayButton.Size = new System.Drawing.Size(194, 20);
			this.BeginDate.CalendarFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.BeginDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
			this.BeginDate.Location = new System.Drawing.Point(72, 8);
			this.BeginDate.Name = "BeginDate";
			this.BeginDate.NullString = "";
			this.BeginDate.ShowCheckBox = false;
			this.BeginDate.Size = new System.Drawing.Size(96, 20);
			this.BeginDate.TabIndex = 11;
			// 
			// chkExportProtosOK
			// 
			this.chkExportProtosOK.Enabled = false;
			this.chkExportProtosOK.Location = new System.Drawing.Point(152, 80);
			this.chkExportProtosOK.Name = "chkExportProtosOK";
			this.chkExportProtosOK.Size = new System.Drawing.Size(96, 16);
			this.chkExportProtosOK.TabIndex = 10;
			this.chkExportProtosOK.Text = "Executed OK";
			// 
			// btnExportProtos
			// 
			this.btnExportProtos.Location = new System.Drawing.Point(8, 80);
			this.btnExportProtos.Name = "btnExportProtos";
			this.btnExportProtos.Size = new System.Drawing.Size(136, 32);
			this.btnExportProtos.TabIndex = 9;
			this.btnExportProtos.Text = "Export Protocols / Investigators To Arp";
			this.btnExportProtos.Click += new System.EventHandler(this.btnExportProtos_Click);
			// 
			// chkGetActiveProtosExec
			// 
			this.chkGetActiveProtosExec.Enabled = false;
			this.chkGetActiveProtosExec.Location = new System.Drawing.Point(152, 40);
			this.chkGetActiveProtosExec.Name = "chkGetActiveProtosExec";
			this.chkGetActiveProtosExec.Size = new System.Drawing.Size(96, 16);
			this.chkGetActiveProtosExec.TabIndex = 8;
			this.chkGetActiveProtosExec.Text = "Executed OK";
			// 
			// btnGetActiveProtos
			// 
			this.btnGetActiveProtos.Location = new System.Drawing.Point(8, 40);
			this.btnGetActiveProtos.Name = "btnGetActiveProtos";
			this.btnGetActiveProtos.Size = new System.Drawing.Size(136, 32);
			this.btnGetActiveProtos.TabIndex = 7;
			this.btnGetActiveProtos.Text = "Get Active Protocols / Investigators";
			this.btnGetActiveProtos.Click += new System.EventHandler(this.btnGetActiveProtos_Click);
			// 
			// btnAdmissionDaysByCat
			// 
			this.btnAdmissionDaysByCat.Location = new System.Drawing.Point(8, 200);
			this.btnAdmissionDaysByCat.Name = "btnAdmissionDaysByCat";
			this.btnAdmissionDaysByCat.Size = new System.Drawing.Size(136, 32);
			this.btnAdmissionDaysByCat.TabIndex = 23;
			this.btnAdmissionDaysByCat.Text = "Admission Days By Category";
			this.btnAdmissionDaysByCat.Click += new System.EventHandler(this.btnAdmissionDaysByCat_Click);
			// 
			// btnOutpatientVisitsByCat
			// 
			this.btnOutpatientVisitsByCat.Location = new System.Drawing.Point(8, 240);
			this.btnOutpatientVisitsByCat.Name = "btnOutpatientVisitsByCat";
			this.btnOutpatientVisitsByCat.Size = new System.Drawing.Size(136, 32);
			this.btnOutpatientVisitsByCat.TabIndex = 24;
			this.btnOutpatientVisitsByCat.Text = "Outpatient Visits By Category";
			this.btnOutpatientVisitsByCat.Click += new System.EventHandler(this.btnOutpatientDaysByCategory_Click);
			// 
			// btnScatNurseHoursByCat
			// 
			this.btnScatNurseHoursByCat.Location = new System.Drawing.Point(8, 280);
			this.btnScatNurseHoursByCat.Name = "btnScatNurseHoursByCat";
			this.btnScatNurseHoursByCat.Size = new System.Drawing.Size(136, 32);
			this.btnScatNurseHoursByCat.TabIndex = 25;
			this.btnScatNurseHoursByCat.Text = "Scatter Nurse Hours By Category";
			this.btnScatNurseHoursByCat.Click += new System.EventHandler(this.btnTestProtoScatNurseCatHoursCensus_Click);
			// 
			// btnCenIpSb
			// 
			this.btnCenIpSb.Location = new System.Drawing.Point(8, 320);
			this.btnCenIpSb.Name = "btnCenIpSb";
			this.btnCenIpSb.Size = new System.Drawing.Size(136, 32);
			this.btnCenIpSb.TabIndex = 30;
			this.btnCenIpSb.Text = "Census IP/SB Admit/Days By Cat/Age";
			this.btnCenIpSb.Click += new System.EventHandler(this.btnCenIpSb_Click);
			// 
			// btnTestCenOpAge
			// 
			this.btnTestCenOpAge.Location = new System.Drawing.Point(8, 360);
			this.btnTestCenOpAge.Name = "btnTestCenOpAge";
			this.btnTestCenOpAge.Size = new System.Drawing.Size(136, 32);
			this.btnTestCenOpAge.TabIndex = 31;
			this.btnTestCenOpAge.Text = "Census Op Visits By Cat/Age";
			this.btnTestCenOpAge.Click += new System.EventHandler(this.btnTestCenOpAge_Click);
			// 
			// btnTestCenOpHrs
			// 
			this.btnTestCenOpHrs.Location = new System.Drawing.Point(8, 400);
			this.btnTestCenOpHrs.Name = "btnTestCenOpHrs";
			this.btnTestCenOpHrs.Size = new System.Drawing.Size(136, 32);
			this.btnTestCenOpHrs.TabIndex = 33;
			this.btnTestCenOpHrs.Text = "Census Op Visits By Cat/Hours";
			this.btnTestCenOpHrs.Click += new System.EventHandler(this.btnTestCenOpHrs_Click);
			// 
			// btnTestCenPS
			// 
			this.btnTestCenPS.Location = new System.Drawing.Point(8, 440);
			this.btnTestCenPS.Name = "btnTestCenPS";
			this.btnTestCenPS.Size = new System.Drawing.Size(136, 32);
			this.btnTestCenPS.TabIndex = 32;
			this.btnTestCenPS.Text = "Census PS";
			this.btnTestCenPS.Click += new System.EventHandler(this.btnTestCenPS_Click);
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.Add(this.dgActiveProtocols);
			this.tabPage2.Location = new System.Drawing.Point(4, 22);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(768, 476);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "Acitve Protocols";
			// 
			// dgActiveProtocols
			// 
			this.dgActiveProtocols.DataMember = "";
			this.dgActiveProtocols.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgActiveProtocols.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgActiveProtocols.Location = new System.Drawing.Point(0, 0);
			this.dgActiveProtocols.Name = "dgActiveProtocols";
			this.dgActiveProtocols.ReadOnly = true;
			this.dgActiveProtocols.Size = new System.Drawing.Size(768, 476);
			this.dgActiveProtocols.TabIndex = 0;
			// 
			// tabPage4
			// 
			this.tabPage4.Controls.Add(this.dgActiveInvestig);
			this.tabPage4.Location = new System.Drawing.Point(4, 22);
			this.tabPage4.Name = "tabPage4";
			this.tabPage4.Size = new System.Drawing.Size(768, 476);
			this.tabPage4.TabIndex = 3;
			this.tabPage4.Text = "Active Investigators";
			// 
			// dgActiveInvestig
			// 
			this.dgActiveInvestig.DataMember = "";
			this.dgActiveInvestig.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgActiveInvestig.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgActiveInvestig.Location = new System.Drawing.Point(0, 0);
			this.dgActiveInvestig.Name = "dgActiveInvestig";
			this.dgActiveInvestig.ReadOnly = true;
			this.dgActiveInvestig.Size = new System.Drawing.Size(768, 476);
			this.dgActiveInvestig.TabIndex = 1;
			// 
			// tabPage3
			// 
			this.tabPage3.Controls.Add(this.dgExpProtocols);
			this.tabPage3.Location = new System.Drawing.Point(4, 22);
			this.tabPage3.Name = "tabPage3";
			this.tabPage3.Size = new System.Drawing.Size(768, 476);
			this.tabPage3.TabIndex = 2;
			this.tabPage3.Text = "Exported Protocols";
			// 
			// dgExpProtocols
			// 
			this.dgExpProtocols.DataMember = "";
			this.dgExpProtocols.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgExpProtocols.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgExpProtocols.Location = new System.Drawing.Point(0, 0);
			this.dgExpProtocols.Name = "dgExpProtocols";
			this.dgExpProtocols.ReadOnly = true;
			this.dgExpProtocols.Size = new System.Drawing.Size(768, 476);
			this.dgExpProtocols.TabIndex = 0;
			// 
			// tabPage5
			// 
			this.tabPage5.Controls.Add(this.dgExpInvestigators);
			this.tabPage5.Location = new System.Drawing.Point(4, 22);
			this.tabPage5.Name = "tabPage5";
			this.tabPage5.Size = new System.Drawing.Size(768, 476);
			this.tabPage5.TabIndex = 4;
			this.tabPage5.Text = "Exported Investigators";
			// 
			// dgExpInvestigators
			// 
			this.dgExpInvestigators.DataMember = "";
			this.dgExpInvestigators.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgExpInvestigators.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgExpInvestigators.Location = new System.Drawing.Point(0, 0);
			this.dgExpInvestigators.Name = "dgExpInvestigators";
			this.dgExpInvestigators.ReadOnly = true;
			this.dgExpInvestigators.Size = new System.Drawing.Size(768, 476);
			this.dgExpInvestigators.TabIndex = 1;
			// 
			// tabPage6
			// 
			this.tabPage6.Controls.Add(this.dgExpInvProt);
			this.tabPage6.Location = new System.Drawing.Point(4, 22);
			this.tabPage6.Name = "tabPage6";
			this.tabPage6.Size = new System.Drawing.Size(768, 476);
			this.tabPage6.TabIndex = 5;
			this.tabPage6.Text = "Exported InvProt";
			// 
			// dgExpInvProt
			// 
			this.dgExpInvProt.DataMember = "";
			this.dgExpInvProt.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgExpInvProt.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgExpInvProt.Location = new System.Drawing.Point(0, 0);
			this.dgExpInvProt.Name = "dgExpInvProt";
			this.dgExpInvProt.ReadOnly = true;
			this.dgExpInvProt.Size = new System.Drawing.Size(768, 476);
			this.dgExpInvProt.TabIndex = 2;
			// 
			// tabPage7
			// 
			this.tabPage7.Controls.Add(this.dgExpAncillaries);
			this.tabPage7.Location = new System.Drawing.Point(4, 22);
			this.tabPage7.Name = "tabPage7";
			this.tabPage7.Size = new System.Drawing.Size(768, 476);
			this.tabPage7.TabIndex = 6;
			this.tabPage7.Text = "Exported Ancillaries";
			// 
			// dgExpAncillaries
			// 
			this.dgExpAncillaries.DataMember = "";
			this.dgExpAncillaries.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dgExpAncillaries.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgExpAncillaries.Location = new System.Drawing.Point(0, 0);
			this.dgExpAncillaries.Name = "dgExpAncillaries";
			this.dgExpAncillaries.ReadOnly = true;
			this.dgExpAncillaries.Size = new System.Drawing.Size(768, 476);
			this.dgExpAncillaries.TabIndex = 3;
			// 
			// txtProtocols
			// 
			this.txtProtocols.Location = new System.Drawing.Point(432, 280);
			this.txtProtocols.Name = "txtProtocols";
			this.txtProtocols.TabIndex = 34;
			this.txtProtocols.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(280, 256);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(224, 16);
			this.label4.TabIndex = 35;
			this.label4.Text = "Convert title and or long title to proper case.";
			// 
			// chkTitle
			// 
			this.chkTitle.Checked = true;
			this.chkTitle.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chkTitle.Location = new System.Drawing.Point(504, 256);
			this.chkTitle.Name = "chkTitle";
			this.chkTitle.Size = new System.Drawing.Size(48, 16);
			this.chkTitle.TabIndex = 36;
			this.chkTitle.Text = "Title";
			// 
			// chkLongTitle
			// 
			this.chkLongTitle.Checked = true;
			this.chkLongTitle.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chkLongTitle.Location = new System.Drawing.Point(560, 256);
			this.chkLongTitle.Name = "chkLongTitle";
			this.chkLongTitle.Size = new System.Drawing.Size(80, 16);
			this.chkLongTitle.TabIndex = 37;
			this.chkLongTitle.Text = "Long Title";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(280, 280);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(152, 16);
			this.label5.TabIndex = 38;
			this.label5.Text = "SPIDs (comma delimited):";
			// 
			// btnProperCase
			// 
			this.btnProperCase.Location = new System.Drawing.Point(544, 280);
			this.btnProperCase.Name = "btnProperCase";
			this.btnProperCase.Size = new System.Drawing.Size(64, 23);
			this.btnProperCase.TabIndex = 39;
			this.btnProperCase.Text = "Convert";
			this.btnProperCase.Click += new System.EventHandler(this.btnProperCase_Click);
			// 
			// FormArpUtils
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(824, 534);
			this.Controls.Add(this.tabControl1);
			this.Name = "FormArpUtils";
			this.Text = "FormArpUtils";
			this.Load += new System.EventHandler(this.FormArpUtils_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.EndDate.Calendar)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.EndDate)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.BeginDate.Calendar)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.BeginDate)).EndInit();
			this.tabPage2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgActiveProtocols)).EndInit();
			this.tabPage4.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgActiveInvestig)).EndInit();
			this.tabPage3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgExpProtocols)).EndInit();
			this.tabPage5.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgExpInvestigators)).EndInit();
			this.tabPage6.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgExpInvProt)).EndInit();
			this.tabPage7.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgExpAncillaries)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region config settings / load and close
		private void FormArpUtils_Load(object sender, System.EventArgs e)
		{
			GetConfigSettings();
			SetConfigSettings();
		}

		private void GetConfigSettings()
		{
			StringBuilder sb = new StringBuilder();

			SqlConnection conn = DataAccess.GetSqlConnection();
			conn.Open();
			string sql = "SELECT * FROM ArpConfigSettings";
			SqlCommand cmd = new SqlCommand(sql, conn);

			SqlDataReader reader = null;
			_htSettings = new Hashtable();

			string key;
			string valu;

			try
			{
				reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
				while (reader.Read())
				{
					key = reader.GetString(0);
					if (reader.IsDBNull(1))
						valu = "";
					else
						valu = reader.GetString(1);
					this._htSettings.Add(key, valu);
				}
			}
			catch (Exception ex)
			{
				sb.Append("Error in retrieving config settings");
				sb.Append(Environment.NewLine);
				sb.Append(ex.Message);
				MessageBox.Show(this, sb.ToString(), "Retieve Config Setting Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			finally
			{
				if (reader != null)
					reader.Close();
				if (conn != null)
					conn.Dispose();
			}

		}

		private void SetConfigSettings()
		{
			string valu;
			_exportsCleaned = false;

			valu = this._htSettings["BeginDate"].ToString();
			if (valu.Length == 0)
			{
				BeginDate.Value = DateTime.Today;
				BeginDate.IsNullDate = true;
			}
			else
				BeginDate.Value = DateTime.Parse(valu);


			valu = this._htSettings["EndDate"].ToString();
			if (valu.Length == 0)
			{
				EndDate.Value = DateTime.Today;
				EndDate.IsNullDate = true;
			}
			else
				EndDate.Value = DateTime.Parse(valu);

			valu = this._htSettings["ActiveProtocols"].ToString();
			if (valu == "True")
			{
				if (SetActiveProtocolsDataSource())  //gets the data table for ArpActiveProtocols
				{
					if (SetActiveInvestigatorsDataSource())
						this.chkGetActiveProtosExec.Checked = true;
				}
			}

			valu = this._htSettings["ExportProtocols"].ToString();
			if (valu == "True")
				if (SetExportedProtocolDataSorce())
					if (SetExportedInvestigatorDataSorce())
						if (SetExportedInvProtDataSorce())
							this.chkExportProtosOK.Checked = true;

			valu = this._htSettings["ExportAncillaries"].ToString();
			if (valu == "True")
				if (this.SetExportedAncillariesDataSorce())
					this.chkExpAncillaries.Checked = true;
		}

		private void SaveConfigSettings()
		{
			string valu = "";
			bool bValu = false;

			if (!BeginDate.IsNullDate)
				valu = BeginDate.Value.ToShortDateString();

			if (valu != this._htSettings["BeginDate"].ToString())
				UpdateConfigSetting("BeginDate", valu);

			valu = "";
			if (!EndDate.IsNullDate)
				valu = EndDate.Value.ToShortDateString();

			if (valu != this._htSettings["EndDate"].ToString())
				UpdateConfigSetting("EndDate", valu);

			bValu = bool.Parse(this._htSettings["ActiveProtocols"].ToString());
			if (bValu != this.chkGetActiveProtosExec.Checked)
				UpdateConfigSetting("ActiveProtocols", this.chkGetActiveProtosExec.Checked.ToString());

			bValu = bool.Parse(this._htSettings["ExportProtocols"].ToString());
			if (bValu != this.chkExportProtosOK.Checked)
				UpdateConfigSetting("ExportProtocols", this.chkExportProtosOK.Checked.ToString());
		}

		private void UpdateConfigSetting(string name, string valu)
		{
			StringBuilder sb = new StringBuilder();
			SqlConnection conn = DataAccess.GetSqlConnection();
			try
			{
				conn.Open();
				string sql = "UPDATE ArpConfigSettings SET valu ='" + valu + "'" +
					" WHERE Name ='" + name + "'";

				SqlCommand cmd = new SqlCommand(sql, conn);
				cmd.ExecuteNonQuery();
			}
			catch (Exception ex)
			{
				sb.Append("Error in updating config settings");
				sb.Append(Environment.NewLine);
				sb.Append(ex.Message);
				MessageBox.Show(this, sb.ToString(), "Update Config Setting Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			finally
			{
				if (conn != null)
					conn.Dispose();
			}
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			SaveConfigSettings();
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		#endregion config settings / load and close

		private bool VerifyDates(out string message)
		{
			message = "";
			if (BeginDate.IsNullDate || EndDate.IsNullDate)
			{
				message = "Enter both a Begin Date and an End Date";
				return false;
			}

			if (BeginDate.Value.CompareTo(EndDate.Value) > -1)
			{
				message = "End Date must be greater than Begin Date";
				return false;
			}
			return true;
		}

		#region active protocols / investigators
		private void btnGetActiveProtos_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			StringBuilder sb = new StringBuilder();

			if (this.chkGetActiveProtosExec.Checked)
			{
				sb.Append("Get active protocols / investigators has previously been executed.");
				sb.Append(Environment.NewLine);
				sb.Append("All previous census information will have to be re-executed.");
				sb.Append(Environment.NewLine);
				sb.Append("Do you want to continue?");
				if (MessageBox.Show(this, sb.ToString(), "Confirm Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
					return;
			}

			this.chkGetActiveProtosExec.Checked = false;
			try
			{
				this.dgActiveProtocols.DataSource = null;
				this.dgActiveInvestig.DataSource = null;

				//need to clean all previous steps that were executed 			
				//truncate tables				
				ArpUtils.TruncateTable("ArpActiveProtocols");
				ArpUtils.TruncateTable("ArpActiveInvestigators");


				if (this.chkExportProtosOK.Checked)
				{
					this.chkExportProtosOK.Checked = false;
					if (!CleanArpExports())
						return;
					_exportsCleaned = true;
				}

				//protocols
				ArpUtils.SetActiveProtocols(BeginDate.Value, EndDate.Value);
				if (!SetActiveProtocolsDataSource())
					return;
				DataTable dtActiveProtocols = (DataTable)this.dgActiveProtocols.DataSource;

				//investigators
				ArpUtils.SetActiveInvestigators(dtActiveProtocols, BeginDate.Value, EndDate.Value);
				SetActiveInvestigatorsDataSource();

				this.chkGetActiveProtosExec.Checked = true;
				MessageBox.Show("GetActiveProtos Completed");
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
		}

		private bool SetActiveProtocolsDataSource()
		{
			this.dgActiveProtocols.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetActiveProtocols();

				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Active Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgActiveProtocols.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			}
		}

		private bool SetActiveInvestigatorsDataSource()
		{
			this.dgActiveInvestig.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetActiveInvestigators();

				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Active Investigators Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgActiveInvestig.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			}
		}
		#endregion active protocols / investigators

		private bool CleanArpExports()
		{
			try
			{
				//
				this.dgExpInvestigators.DataSource = null;
				this.dgExpInvProt.DataSource = null;
				this.dgExpProtocols.DataSource = null;

				//clean existing arp tables
				ArpUtils.CleanArpTable("SPJPRO");
				ArpUtils.CleanArpTable("SPJINV");
				ArpUtils.CleanArpTable("INVESTIG");

				//resets autonumbers
				if (!CompactDB())
					return false;
				//rename the arp db with the compact db
				if (!ReplaceDBWithCompactDB())
					return false;

				return true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			}
		}

		private void btnExportProtos_Click(object sender, System.EventArgs e)
		{
			StringBuilder sb = new StringBuilder();

			if (this.chkExportProtosOK.Checked)
			{
				sb.Append("Export active protocols has already been executed.");
				sb.Append(Environment.NewLine);
				sb.Append("Do you want re-do this step?");
				if (MessageBox.Show(this, sb.ToString(), "Confirm Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
					return;
			}

			Cursor.Current = Cursors.WaitCursor;
			this.chkExportProtosOK.Checked = false;
			DataTable dt = null;

			//clean and compact access database so autonumbers begin with 0
			if (!_exportsCleaned)
				if (!this.CleanArpExports())
					return;

			//export protocols
			dt = (DataTable)this.dgActiveProtocols.DataSource;
			foreach (DataRow dr in dt.Rows)
			{
				try
				{
					//this gets current info from sql server that the apr table needs.
					DataRow dr2 = ArpUtils.GetProtocolArpInfo((int)dr["ProtocolID"]);
					//add to arp table
					int arpID = ArpUtils.AddProtocolToArp(dr2, dr["ProtocolNumber"].ToString(), (int)dr["SPID"]);
					//update sql server table with arp id
					ArpUtils.UpdateActiveProtocolWithArpID(arpID, (int)dr["ProtocolID"]);
				}

				catch (Exception ex)
				{
					MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK,
						MessageBoxIcon.Error);
					return;
				}
			}
			//need to reset this with updated arp id's
			SetActiveProtocolsDataSource();
			SetExportedProtocolDataSorce();

			//export investigators
			dt = (DataTable)this.dgActiveInvestig.DataSource;
			foreach (DataRow dr in dt.Rows)
			{
				try
				{
					DataRow dr2 = ArpUtils.GetInvestigatorArpInfo((int)dr["InvestigatorID"]);
					int arpID = ArpUtils.AddInvestigatorToArp(dr2, dr["Name"].ToString());
					if (arpID == 79)
						Console.WriteLine("ArpID: " + arpID + " InvID: " + (int)dr["InvestigatorID"]);
					ArpUtils.UpdateActiveInvestigatorWithArpID(arpID, (int)dr["InvestigatorID"]);
				}
				catch (Exception ex)
				{
					MessageBox.Show(this, ex.Message, "Get Active Investigators Failed", MessageBoxButtons.OK,
						MessageBoxIcon.Error);
					return;
				}
			}

			SetActiveInvestigatorsDataSource();
			SetExportedInvestigatorDataSorce();

			//insert into arp SPJINV
			dt = (DataTable)this.dgActiveProtocols.DataSource;
			foreach (DataRow dr in dt.Rows)
			{
				try
				{
					//add to arp table
					ArpUtils.SetInvProtToArp((int)dr["ProtocolID"], (int)dr["ArpID"]);
				}
				catch (Exception ex)
				{
					MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK,
						MessageBoxIcon.Error);
					return;
				}
			}

			SetExportedInvProtDataSorce();
			_exportsCleaned = false;
			chkExportProtosOK.Checked = true;
			MessageBox.Show("ExportProtos Completed");
		}

		private bool SetExportedInvProtDataSorce()
		{
			this.dgExpInvProt.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetArpDataTable("SPJINV");
				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Arp SPJINV Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgExpInvProt.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Arp SPJINV Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		private bool SetExportedAncillariesDataSorce()
		{
			this.dgExpAncillaries.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetArpDataTable("ANCILLARIES");
				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Arp Ancillaries Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgExpAncillaries.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Arp Protocols Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		private bool SetExportedProtocolDataSorce()
		{
			this.dgExpProtocols.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetArpDataTable("SPJPRO");
				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Arp Protocols Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgExpProtocols.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Arp Protocols Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		private bool SetExportedInvestigatorDataSorce()
		{
			this.dgExpInvestigators.DataSource = null;
			try
			{
				DataTable dt = ArpUtils.GetArpDataTable("INVESTIG");
				if (dt == null)
				{
					MessageBox.Show(this, "DataTabe is null", "Get Arp Investigators Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
					return false;
				}
				else
				{
					this.dgExpInvestigators.DataSource = dt;
					return true;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Investigators Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		#region test
		private void btnTestArpConn_Click(object sender, System.EventArgs e)
		{
			chkConn.Checked = false;
			try
			{
				if (ArpUtils.TestArpConnection())
					chkConn.Checked = true;
				else
					MessageBox.Show(this, "Could not open connection", "Arp Connection Not Open", MessageBoxButtons.OK, MessageBoxIcon.Stop);
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Arp Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}

		}

		private bool CompactDB()
		{
			try
			{
				ArpUtils.CompactDB();
				return true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Compact Database Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		private bool ReplaceDBWithCompactDB()
		{
			try
			{
				ArpUtils.ReplaceDBWithCompactDB();
				return true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Replace With Compact Database Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return false;
			}
		}

		private void btnCompact_Click(object sender, System.EventArgs e)
		{
			CompactDB();
		}

		private void btnReplace_Click(object sender, System.EventArgs e)
		{
			ReplaceDBWithCompactDB();
		}

		private void btnMisc_Click(object sender, System.EventArgs e)
		{
			DataTable dt = (DataTable)this.dgActiveProtocols.DataSource;
			try
			{
				ArpUtils.SetActiveInvestigators(dt, DateTime.Today, DateTime.Today);
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		#endregion test

		private void btnExpAncillaries_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			StringBuilder sb = new StringBuilder();

			if (this.chkExpAncillaries.Checked)
			{
				sb.Append("Export ancillaries has already been executed.");
				sb.Append(Environment.NewLine);
				sb.Append("Do you want re-do this step?");
				if (MessageBox.Show(this, sb.ToString(), "Confirm Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
					return;
			}

			Cursor.Current = Cursors.WaitCursor;
			this.chkExpAncillaries.Checked = false;
			this.dgExpAncillaries.DataSource = null;

			DateTime dtStart;
			DateTime dtEnd;
			try
			{
				//initialize ARP and Crema tables
				ArpUtils.CleanArpTable("ANCILLARIES");
				//sets fields to 0 in the PCCAR arp tables
				ArpUtils.InitializeArpPCCARTables();
				ArpUtils.TruncateTable("aaAncillaryCensusIn");
				ArpUtils.TruncateTable("aaAncillaryCensusOut");

				//test for missing ancillary rates;
				ArrayList alMissingIDs = ArpUtils.GetMissingAncillaryRates(BeginDate.Value, EndDate.Value);
				if (alMissingIDs.Count > 0)
				{
					sb = new StringBuilder();
					sb.Append("There are ancillary rates not covering ancillaries for the folling cost centers:");
					sb.Append(Environment.NewLine);
					sb.Append("IDs: ");
					foreach (int i in alMissingIDs)
						sb.Append(i.ToString() + ", ");
					//remove the last ','
					sb.Remove(sb.Length - 1, 1);
					sb.Append(Environment.NewLine);
					sb.Append("You must correct the missing rates before continuing!");

					MessageBox.Show(this, sb.ToString(), "Missing Ancillary Rates", MessageBoxButtons.OK, MessageBoxIcon.Warning);
					return;
				}

				//dt mimics the arp access ancillary table (columns and types)
				//by setting the columns for the dataTable
				DataTable dt = InitializeAncillaryDT();

				//dt (costCenter column) is filled here with distinct cost centers
				ArpUtils.SetDistinctAncillaryCostCenter(BeginDate.Value, EndDate.Value, dt);

				//temp				
				//insert into temp table (aaAncillaryCensusIn) all admission ancillaries for dates
				ArpUtils.SetAncillaryCensusIn(BeginDate.Value, EndDate.Value);

				//out patient
				ArpUtils.SetAncillaryCensusOut(BeginDate.Value, EndDate.Value);

				//get the start dates for rate changes
				ArrayList al = ArpUtils.GetAncillaryRateChangeDates(BeginDate.Value, EndDate.Value);

				//TODO - It looks like arp2xml limits you to 2 rate changes for the year.  If so, we have to 
				//use only two rate changes.

				//first start date is the report start date
				dtStart = BeginDate.Value;

				//Group by center,category,rate for each rate change date								
				int change;
				DateTime dtChange;
				if (al.Count == 0)
				{
					dtEnd = EndDate.Value;
					for (int category = 2; category < 4; category++)
					{
						ArpUtils.GetAncillaryAdmissionCensusGrouped(dt, 1, category, dtStart, dtEnd);
						ArpUtils.GetAncillaryOutCensusGrouped(dt, 1, category, dtStart, dtEnd);
					}
				}
				else
				{
					change = 1;
					dtChange = (DateTime)al[change - 1];
					dtEnd = dtChange.AddDays(-1);
					while (change < al.Count + 2)
					{
						for (int category = 2; category < 4; category++)
						{
							ArpUtils.GetAncillaryAdmissionCensusGrouped(dt, change, category, dtStart, dtEnd);
							ArpUtils.GetAncillaryOutCensusGrouped(dt, change, category, dtStart, dtEnd);
						}

						change++;
						dtStart = dtChange;
						if (change == al.Count + 1)
							dtEnd = EndDate.Value;
						else if (change == al.Count + 2)
							break;
						else
						{
							dtChange = (DateTime)al[change - 1];
							dtEnd = dtChange.AddDays(-1);
						}
					}
				}
				ArpUtils.AddToArpAncillaries(dt);

				//patient care ancillary stuff
				dtStart = BeginDate.Value;
				if (al.Count == 0)
				{
					dtEnd = EndDate.Value;
					ArpUtils.SetAncillaryAdmissionPatientCare(1, dtStart, dtEnd);
					ArpUtils.SetAncillaryOutpatientPatientCare(1, dtStart, dtEnd);

					//need to set aaCombineCensus for time period
					//this is use to get patient care days
					ArpUtils.TruncateTable("aaCombineCensus");
					ArpUtils.SetAdmissionCensus(dtStart, dtEnd);
					ArpUtils.SetOutpatientCensus(dtStart, dtEnd);

					ArpUtils.SetAdmissionDaysPatientCare(1);
					ArpUtils.SetOutpatientDaysPatientCare(1);
				}
				else
				{
					change = 1;
					dtChange = (DateTime)al[change - 1];
					dtEnd = dtChange.AddDays(-1);
					while (change < al.Count + 2)
					{
						ArpUtils.TruncateTable("aaCombineCensus");
						ArpUtils.SetAncillaryAdmissionPatientCare(change, dtStart, dtEnd);
						ArpUtils.SetAncillaryOutpatientPatientCare(change, dtStart, dtEnd);

						//need to set aaCombineCensus for time period
						//this is use to get patient care days					
						ArpUtils.TruncateTable("aaCombineCensus");
						ArpUtils.SetAdmissionCensus(dtStart, dtEnd);
						ArpUtils.SetOutpatientCensus(dtStart, dtEnd);

						ArpUtils.SetAdmissionDaysPatientCare(change);
						ArpUtils.SetOutpatientDaysPatientCare(change);

						change++;
						dtStart = dtChange;
						if (change == al.Count + 1)
							dtEnd = EndDate.Value;
						else if (change == al.Count + 2)
							break;
						else
						{
							dtChange = (DateTime)al[change - 1];
							dtEnd = dtChange.AddDays(-1);
						}
					}
				}

				if (this.SetExportedAncillariesDataSorce())
					this.chkExpAncillaries.Checked = true;
				MessageBox.Show("ExpAncillaries Completed");
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, ex.Message, "Get Active Protocols Failed", MessageBoxButtons.OK,
					MessageBoxIcon.Error);
				return;
			}
		}

		private DataTable InitializeAncillaryDT()
		{
			DataTable dt = new DataTable();

			dt.Columns.Add(new DataColumn("CostCenter", typeof(System.String)));
			dt.Columns.Add(new DataColumn("GrossAI1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossBI1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("AdjustI1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossAI2", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossBI2", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("AdjustI2", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossAO1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossBO1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("AdjustO1", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossAO2", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("GrossBO2", typeof(System.Decimal)));
			dt.Columns.Add(new DataColumn("AdjustO2", typeof(System.Decimal)));

			dt.PrimaryKey = new DataColumn[] { dt.Columns["CostCenter"] };
			return dt;
		}

		private void btnExpEthnicity_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			//create aaCombineCensus for full report time set
			Cursor.Current = Cursors.WaitCursor;
			ArpUtils.TruncateTable("aaCombineCensus");
			ArpUtils.SetAdmissionCensus(BeginDate.Value, EndDate.Value);
			ArpUtils.SetOutpatientCensus(BeginDate.Value, EndDate.Value);
			ArpUtils.SetScatterNurseHoursCensus(BeginDate.Value, EndDate.Value);

			DataTable dt = ArpUtils.GetDistinctProtocolPatientCensus();
			ArpUtils.CleanArpTable("SPJETH");
			CompactDB();
			ArpUtils.CalcActiveEthnicityCensus(dt);
			MessageBox.Show("ActiveEthnicityCensus Completed");

		}

		private void btnTestAdmCen_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			Cursor.Current = Cursors.WaitCursor;
			ArpUtils.TruncateTable("aaCombineCensus");
			ArpUtils.SetAdmissionCensus(BeginDate.Value, EndDate.Value);
		}

		private void btnTestOutpatCen_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			Cursor.Current = Cursors.WaitCursor;
			//ArpUtils.TruncateTable("aaOutpatientCensus");
			ArpUtils.SetOutpatientCensus(BeginDate.Value, EndDate.Value);
		}

		private void btnTestScatNursHrs_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			Cursor.Current = Cursors.WaitCursor;
			//ArpUtils.TruncateTable("aaScatterNurseHoursCensus");
			ArpUtils.SetScatterNurseHoursCensus(BeginDate.Value, EndDate.Value);
		}

		private void btnAdmissionDaysByCat_Click(object sender, System.EventArgs e)
		{
			ArpUtils.InitializeProtocolsCensus();
			DataTable dt = ArpUtils.GetProtocolAdmissionCategoryDaysCensus();

			if (dt == null)
				return;

			ArpUtils.SetProtocolAdmissionCategoryDaysCensus(dt);
			MessageBox.Show("AdmissionCategoryDaysCensus Completed");
		}

		private void btnOutpatientDaysByCategory_Click(object sender, System.EventArgs e)
		{
			DataTable dt = ArpUtils.GetProtocolOutpatientCategoryDaysCensus();
			ArpUtils.SetProtocolOutpatientCategoryDaysCensus(dt);
			MessageBox.Show("OutpatientCategoryDaysCensus Completed");
		}

		private void btnTestProtoScatNurseCatHoursCensus_Click(object sender, System.EventArgs e)
		{
			DataTable dt = ArpUtils.GetProtocolScatterNurseCategoryHoursCensus();
			if (dt == null)
				return;

			ArpUtils.SetProtocolScatterNurseCategoryHoursCensus(dt);
			MessageBox.Show("ScatterNurseCategoryHoursCensus Completed");
		}

		private void btnTestMyRound_Click(object sender, System.EventArgs e)
		{

			decimal dec = Convert.ToDecimal(txt1.Text);
			int rnd = ArpUtils.MyRound(dec);
			txt2.Text = rnd.ToString();
		}

		private void btnCenIpSb_Click(object sender, System.EventArgs e)
		{
			ArpUtils.InitializeArpCEN_IPOr_SB("CEN_IP");
			ArpUtils.InitializeArpCEN_IPOr_SB("CEN_SB");
			ArpUtils.SetProtocolAdmissionAgeVisitsDaysCensus();
			MessageBox.Show("CenIpSb Completed");
		}

		private void btnTestCenOpAge_Click(object sender, System.EventArgs e)
		{
			ArpUtils.InitializeArpCEN_OPAGE();
			ArpUtils.SetOutpatientAgeVisitsCategoryCensus();
			MessageBox.Show("CenOpAge Completed");
		}

		private void btnTestCenOpHrs_Click(object sender, System.EventArgs e)
		{
			ArpUtils.InitializeArpCEN_OP();
			ArpUtils.SetOutpatientHoursVisitsCategoryCensus();
			MessageBox.Show("CenOpVisits Completed");
		}

		private void btnTestCenPS_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			ArpUtils.InitializeArpCEN_PS();
			Hashtable ht = ArpUtils.SetDaysOpenHash(BeginDate.Value, EndDate.Value);
			foreach (object o in ht.Keys)
				Console.WriteLine(o.ToString());
			ArpUtils.SetCensusPS(ht, BeginDate.Value, EndDate.Value);
			ArpUtils.UpdateCensusPS(ht);
			MessageBox.Show("CenPS Completed");
		}

		private void btnTestRateChangeDates_Click(object sender, System.EventArgs e)
		{
			string message = "";
			if (!VerifyDates(out message))
			{
				MessageBox.Show(this, message, "Invalid Dates", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}

			ArrayList al = ArpUtils.GetAncillaryRateChangeDates(BeginDate.Value, EndDate.Value);
			foreach (DateTime dt in al)
				Console.WriteLine(dt.ToShortDateString());
		}

		private void btnProperCase_Click(object sender, System.EventArgs e)
		{
			if (txtProtocols.Text.Length == 0)
				MessageBox.Show("Enter protocol spids, seperate with comma.");
			//convert spids text to array of spids
			string[] sa = txtProtocols.Text.Split(',');
			int spid;
			string title = "";
			string longTitle = "";

			string sqlSelect = "SELECT Title,LongTitle FROM Protocol WHERE SPID=";
			string sql1;
			string sqlUpdate = "UPDATE Protocol SET Title=@Title,LongTitle=@LongTitle WHERE SPID=";
			string sql2;

			SqlParameter[] aParams = new SqlParameter[2];
			aParams[0] = new SqlParameter("@Title", SqlDbType.NVarChar, 200, "Title");
			aParams[1] = new SqlParameter("@LongTitle", SqlDbType.NVarChar, 1000, "LongTitle");

			//SqlConnection conn = DataAccess.GetSqlConnection();
			Database db = DatabaseFactory.CreateDatabase();

			try
			{
				foreach (string s in sa)
				{
					spid = Convert.ToInt32(s);
					sql1 = sqlSelect + spid;
					sql2 = sqlUpdate + spid;

					GetTitleFields(sql1, out title, out longTitle);
					aParams[0].Value = title;
					aParams[1].Value = longTitle;

					DbCommand cmd = db.GetSqlStringCommand(sql2);
					DataAccess.AddParamArrayToDbCommand(cmd, aParams);

					int rslt = db.ExecuteNonQuery(cmd);
					if (rslt < 1)
						MessageBox.Show("Could not update spid: " + spid);

				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}

		}

		private void GetTitleFields(string sql, out string title, out string longTitle)
		{
			title = "";
			longTitle = "";

			//SqlConnection conn = DataAccess.GetSqlConnection();
			IDataReader reader = null;
			try
			{
				//conn.Open();
				reader = DataAccess.GetDataReader(sql);
				if (reader.Read())
				{
					title = reader.GetString(0);
					title = Microsoft.VisualBasic.Strings.StrConv(title, VbStrConv.ProperCase, 1);

					longTitle = Microsoft.VisualBasic.Strings.StrConv(reader.GetString(1), VbStrConv.ProperCase, 1);
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				if (reader != null)
					reader.Close();
				//if(conn != null)
				//    conn.Dispose();

			}


		}

	}
}
